package com.anjubao.parking.municipal.roadside.controller;

import com.anjubao.parking.municipal.common.dto.ApiResult;
import com.anjubao.parking.municipal.roadside.form.ParkingLotForm;
import com.anjubao.parking.municipal.roadside.service.ParkingLotService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sync/lot")
public class ParkingLotController {

    private static final Logger logger = LoggerFactory.getLogger(ParkingLotController.class);
    @Autowired
    private ParkingLotService parkingLotService;
    /**
     * 车场信息（1：新增，2：修改）
     * @return
     */
    @PostMapping(value = "/{type}")
    public ApiResult syncParkingLot(@PathVariable int type, @RequestBody @Validated ParkingLotForm parkLotForm){
        logger.info("【新增或修改车场信息】,参数:{}", parkLotForm);
        parkingLotService.syncParkingLot(type,parkLotForm);
        return ApiResult.success();
    }

    /**
     * 删除车场信息
     * @param parkingLotCode
     * @return
     */
    @GetMapping(value = "/{parkingLotCode}/delete")
    public ApiResult deleteParkingLot(@PathVariable @Validated String parkingLotCode){
        logger.info("【删除车场】，车场code:{}", parkingLotCode);
        parkingLotService.deleteParkingLot(parkingLotCode);
        return ApiResult.success();
    }
}
